home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
9-Digit Zip Code Directory
/
9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO
/
z4src.zip
/
DICRC.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-15
|
3KB
|
119 lines
//----------------------------------------------------------------------------
// MODULE DESCRIPTION
//
// Module: dicrc.c
// Title: Data File I/O Library
// Notice: John M. Weeder
// Copyright (c) 1993. All rights reserved.
// This module contains proprietary information and should be
// treated as confidential.
//
//----------------------------------------------------------------------------
// MAINTENANCE HISTORY
//
// $Workfile$
// $Revision$
// $Author$
// $Date$
// $Log$
//
//----------------------------------------------------------------------------
// MODULE NARRATIVE
//
//
// This module contains code to the CRC for a logical data file.
//
// The code in this module should be written entirely in C.
// Do not use any C++ constructs.
//
// This module is portable to:
// DOS 3.X+
// MS Windows 3.X+
// OS/2 2.X+
// OS/2 2.0 PM
// SCO UNIX.
//
// The following compilers are supported:
// MSC 6.0A
// MSC/C++ 7.0
// Borland C++ 3.1 for DOS
// Borland C++ 1.0 for OS/2 2.X
// SCO UNIX cc
//
//----------------------------------------------------------------------------
#include <di.h>
//----------------------------------------------------------------------------
// Description: Update the CRC of a data area
// Parameters: pcsz Physical file name.
// pcszLogical Logical file to update
// usType Logical file type
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_E DioCrc(PCSZ pcsz, PCSZ pcszLogical, USHORT usType, PCRC pcrc)
{
HPF hpf;
HLF hlf = -1;
BOOL fUser;
BOOL fResult = FALSE;
HF hf;
SIZET cDir;
FPOS flen;
CRC crc;
DATADIR dir;
if (pcrc)
*pcrc = 0;
if (HIUSHORT(pcsz)) // Open physical file
{
if (!DioOpenPhysical(pcsz, &hpf, TRUE))
return FALSE;
fUser = FALSE;
}
else
{
hpf = LOUSHORT(pcsz);
Assert(hpf >= 0 && hpf < MAX_PHYSICAL_FILES);
Assert(di.physical[hpf].fUsed);
fUser = TRUE;
}
// Not open logical file
if (!DioOpenLogical(pcszLogical, &hlf, usType))
goto ERROR_EXIT;
cDir = di.logical[hlf].cDir;
hf = di.logical[hlf].hf;
flen = di.logical[hlf].flen;
if ((flen % (FPOS)sizeof(DATAHDR)) != 0)
{
flen += sizeof(DATAHDR); // Round up to nearest multiple of
flen /= sizeof(DATAHDR); // header size
flen *= sizeof(DATAHDR);
}
// Calculate crc
if (!FileCrc(hf, &crc, flen, di.logical[hlf].fbase))
goto ERROR_EXIT;
// Read directory
if (!DioDirRead(hpf, cDir, &dir))
goto ERROR_EXIT;
dir.crcData = crc;
if (pcrc)
*pcrc = crc;
// Write updated header
if (!DioDirWrite(hpf, cDir, &dir))
goto ERROR_EXIT;
fResult = TRUE;
ERROR_EXIT:
if (hlf >= 0)
DioCloseLogical(hlf);
if (!fUser)
DioClosePhysical(hpf);
return fResult;
}
//----------------------------------------------------------------------------
//------------------------------- End of File --------------------------------
//----------------------------------------------------------------------------